<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>订单列表 - MarsPay支付系统</title>
    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Bootstrap Icons -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.0/font/bootstrap-icons.css" rel="stylesheet">
    <style>
        :root {
            --primary-color: #ffe60f;
            --primary-dark: #ffd700;
            --primary-light: #fff8c4;
            --text-dark: #333;
            --text-gray: #666;
        }
        
        body {
            background: linear-gradient(180deg, #fff 0%, #f8f8f8 100%);
            min-height: 100vh;
            font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
            padding-bottom: 40px;
        }
        
        .navbar-custom {
            background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
            box-shadow: 0 2px 15px rgba(255, 230, 15, 0.3);
            padding: 1rem 0;
        }
        
        .navbar-brand {
            font-size: 1.5rem;
            font-weight: bold;
            color: var(--text-dark) !important;
        }
        
        .btn-back {
            background: white;
            color: var(--text-dark);
            border: 2px solid rgba(0, 0, 0, 0.1);
            padding: 0.5rem 1.5rem;
            border-radius: 50px;
            font-weight: 500;
            transition: all 0.3s ease;
        }
        
        .btn-back:hover {
            border-color: var(--primary-color);
            background: var(--primary-light);
        }
        
        .page-header {
            padding: 40px 0 30px;
        }
        
        .page-title {
            font-size: 2rem;
            font-weight: bold;
            color: var(--text-dark);
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .order-card {
            background: white;
            border-radius: 16px;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
            margin-bottom: 20px;
            overflow: hidden;
            transition: all 0.3s ease;
        }
        
        .order-card:hover {
            box-shadow: 0 8px 30px rgba(255, 230, 15, 0.2);
            transform: translateY(-4px);
        }
        
        .order-header {
            background: linear-gradient(135deg, var(--primary-light) 0%, #fff 100%);
            padding: 15px 20px;
            border-bottom: 2px solid var(--primary-color);
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        
        .order-no {
            font-family: 'Courier New', monospace;
            font-weight: 600;
            color: var(--text-dark);
            font-size: 0.95rem;
        }
        
        .order-body {
            padding: 20px;
        }
        
        .order-info-row {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 12px 0;
            border-bottom: 1px dashed #e8e8e8;
        }
        
        .order-info-row:last-child {
            border-bottom: none;
        }
        
        .info-label {
            color: var(--text-gray);
            font-size: 0.95rem;
        }
        
        .info-value {
            font-weight: 600;
            color: var(--text-dark);
        }
        
        .amount-value {
            font-size: 1.5rem;
            font-weight: bold;
            color: #ff6b6b;
        }
        
        .badge-custom {
            padding: 6px 12px;
            border-radius: 20px;
            font-size: 0.85rem;
            font-weight: 500;
        }
        
        .badge-wait {
            background: #fff7e6;
            color: #fa8c16;
            border: 1px solid #ffd591;
        }
        
        .badge-paying {
            background: #e6f7ff;
            color: #1890ff;
            border: 1px solid #91d5ff;
        }
        
        .badge-success {
            background: #f6ffed;
            color: #52c41a;
            border: 1px solid #b7eb8f;
        }
        
        .badge-failed {
            background: #fff1f0;
            color: #ff4d4f;
            border: 1px solid #ffa39e;
        }
        
        .order-actions {
            display: flex;
            gap: 10px;
            margin-top: 15px;
            padding-top: 15px;
            border-top: 1px dashed #e8e8e8;
        }
        
        .btn-pay {
            background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
            color: var(--text-dark);
            border: none;
            padding: 8px 20px;
            border-radius: 50px;
            font-weight: 600;
            transition: all 0.3s ease;
        }
        
        .btn-pay:hover {
            transform: scale(1.05);
            box-shadow: 0 4px 12px rgba(255, 230, 15, 0.4);
        }
        
        .btn-query {
            background: white;
            color: var(--text-dark);
            border: 2px solid #e8e8e8;
            padding: 8px 20px;
            border-radius: 50px;
            font-weight: 500;
            transition: all 0.3s ease;
        }
        
        .btn-query:hover {
            border-color: var(--primary-color);
            background: var(--primary-light);
        }
        
        .empty-state {
            text-align: center;
            padding: 80px 20px;
            background: white;
            border-radius: 16px;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
        }
        
        .empty-icon {
            font-size: 5rem;
            color: #d9d9d9;
            margin-bottom: 20px;
        }
        
        .empty-text {
            color: var(--text-gray);
            margin-bottom: 30px;
            font-size: 1.1rem;
        }
        
        .payment-type-icon {
            display: inline-flex;
            align-items: center;
            gap: 5px;
            padding: 4px 10px;
            border-radius: 20px;
            font-size: 0.85rem;
        }
        
        .wechat-pay {
            background: #f0fdf4;
            color: #15803d;
        }
        
        .alipay-pay {
            background: #eff6ff;
            color: #1e40af;
        }
    </style>
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar navbar-custom">
        <div class="container">
            <a class="navbar-brand" href="/">
                <i class="bi bi-rocket-takeoff"></i> MarsPay
            </a>
            <a href="/" class="btn btn-back">
                <i class="bi bi-house"></i> 返回首页
            </a>
        </div>
    </nav>

    <!-- 页头 -->
    <div class="page-header">
        <div class="container">
            <h2 class="page-title">
                <i class="bi bi-receipt"></i>
                我的订单
            </h2>
        </div>
    </div>

    <!-- 主要内容 -->
    <div class="container">
        <!-- 订单列表 -->
        <div th:if="${!#lists.isEmpty(orders)}">
            <div class="order-card" th:each="order : ${orders}">
                <div class="order-header">
                    <span class="order-no" th:text="'订单号：' + ${order.orderNo}">ORDER001</span>
                    <span th:if="${order.status == 0}" class="badge-custom badge-wait">待支付</span>
                    <span th:if="${order.status == 1}" class="badge-custom badge-paying">支付中</span>
                    <span th:if="${order.status == 2}" class="badge-custom badge-success">支付成功</span>
                    <span th:if="${order.status == 3}" class="badge-custom badge-failed">支付失败</span>
                    <span th:if="${order.status == 4}" class="badge-custom badge-failed">已退款</span>
                    <span th:if="${order.status == 5}" class="badge-custom badge-failed">已关闭</span>
                </div>
                <div class="order-body">
                    <div class="order-info-row">
                        <span class="info-label">商品名称</span>
                        <span class="info-value" th:text="${order.productName}">商品名称</span>
                    </div>
                    <div class="order-info-row">
                        <span class="info-label">支付金额</span>
                        <span class="amount-value" th:text="'¥' + ${order.amount}">¥0.00</span>
                    </div>
                    <div class="order-info-row">
                        <span class="info-label">支付方式</span>
                        <span>
                            <span th:if="${order.paymentType == 'WECHAT'}" class="payment-type-icon wechat-pay">
                                <i class="bi bi-wechat"></i> 微信支付
                            </span>
                            <span th:if="${order.paymentType == 'ALIPAY'}" class="payment-type-icon alipay-pay">
                                <i class="bi bi-alipay"></i> 支付宝
                            </span>
                            <span th:if="${order.paymentType == null}" class="badge-custom" style="background: #f5f5f5; color: #999;">
                                未选择
                            </span>
                        </span>
                    </div>
                    <div class="order-info-row">
                        <span class="info-label">创建时间</span>
                        <span class="info-value" th:text="${#temporals.format(order.createTime, 'yyyy-MM-dd HH:mm')}">2025-01-01 12:00</span>
                    </div>
                    
                    <div class="order-actions">
                        <button th:if="${order.status == 0}" 
                                class="btn btn-pay" 
                                th:data-order-id="${order.id}"
                                onclick="payOrder(this.dataset.orderId)">
                            <i class="bi bi-credit-card"></i> 去支付
                        </button>
                        <button class="btn btn-query" 
                                th:data-order-no="${order.orderNo}"
                                onclick="queryOrder(this.dataset.orderNo)">
                            <i class="bi bi-search"></i> 查询状态
                        </button>
                    </div>
                </div>
            </div>
        </div>
        
        <!-- 空状态 -->
        <div th:if="${#lists.isEmpty(orders)}" class="empty-state">
            <div class="empty-icon">
                <i class="bi bi-inbox"></i>
            </div>
            <p class="empty-text">暂无订单记录</p>
            <a href="/" class="btn btn-pay" style="padding: 12px 40px; font-size: 1.1rem;">
                <i class="bi bi-cart-plus"></i> 去购物
            </a>
        </div>
    </div>

    <!-- 支付方式选择模态框 -->
    <div class="modal fade" id="paymentModal" tabindex="-1">
        <div class="modal-dialog modal-dialog-centered">
            <div class="modal-content" style="border-radius: 20px; border: none;">
                <div class="modal-header" style="background: linear-gradient(135deg, var(--primary-light) 0%, #fff 100%); border-bottom: 2px solid var(--primary-color);">
                    <h5 class="modal-title fw-bold">
                        <i class="bi bi-credit-card"></i> 选择支付方式
                    </h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>
                <div class="modal-body p-4">
                    <div class="row g-3">
                        <div class="col-6">
                            <button class="btn w-100 p-4" style="background: #07c160; color: white; border-radius: 12px; border: none;" onclick="pay('wechat')">
                                <i class="bi bi-wechat" style="font-size: 2rem;"></i><br>
                                <span class="mt-2 d-block">微信支付</span>
                            </button>
                        </div>
                        <div class="col-6">
                            <button class="btn w-100 p-4" style="background: #1678ff; color: white; border-radius: 12px; border: none;" onclick="pay('alipay')">
                                <i class="bi bi-alipay" style="font-size: 2rem;"></i><br>
                                <span class="mt-2 d-block">支付宝</span>
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        let currentOrderId = null;
        let paymentModal = null;

        document.addEventListener('DOMContentLoaded', function() {
            paymentModal = new bootstrap.Modal(document.getElementById('paymentModal'));
        });

        function payOrder(orderId) {
            currentOrderId = orderId;
            paymentModal.show();
        }

        function pay(type) {
            if (!currentOrderId) {
                alert('订单ID不存在');
                return;
            }

            paymentModal.hide();

            if (type === 'wechat') {
                window.location.href = `/pay/wechat/${currentOrderId}`;
            } else if (type === 'alipay') {
                const form = document.createElement('form');
                form.method = 'POST';
                form.action = `/pay/alipay/${currentOrderId}`;
                document.body.appendChild(form);
                form.submit();
            }
        }

        function queryOrder(orderNo) {
            const btn = event.target;
            const originalText = btn.innerHTML;
            btn.innerHTML = '<i class="bi bi-hourglass-split"></i> 查询中...';
            btn.disabled = true;

            fetch(`/pay/query/${orderNo}`)
                .then(response => response.json())
                .then(data => {
                    if (data.code === 200) {
                        const order = data.data.order;
                        const statusDesc = data.data.statusDesc;
                        alert(`📋 订单详情\n\n订单号：${order.orderNo}\n商品：${order.productName}\n金额：¥${order.amount}\n状态：${statusDesc}`);
                        location.reload();
                    } else {
                        alert('❌ 查询失败：' + data.message);
                    }
                })
                .catch(error => {
                    console.error('Error:', error);
                    alert('❌ 查询失败，请重试');
                })
                .finally(() => {
                    btn.innerHTML = originalText;
                    btn.disabled = false;
                });
        }
    </script>
</body>
</html>
